package com.jinxin.platform.cdcardpassmgr.utils;

import org.springframework.util.StringUtils;

import java.math.BigDecimal;
import java.util.Random;
import java.util.UUID;

public class Utils {

    public static String getUuid() {
        UUID uuid = UUID.randomUUID();
        return uuid.toString().replace("-", "");
    }

    /**
     * 获取位数为7位的随机数
     *
     * @return
     */
    public static String getRandom() {
        Random random = new Random();
        int nextInt = random.nextInt(9000000);
        nextInt = nextInt + 1000000;
        return nextInt + "";
    }

    public static String getRandom6() {
        Random random = new Random();
        int nextInt = random.nextInt(900000);
        nextInt = nextInt + 100000;
        return nextInt + "";
    }
    // 是否是奇数
    public static boolean isOdd(int num){
        return (num&1)==1;
    }

    // 判断字符串是否全是数字
    public static boolean isNumeric(String str){
        for (int i = 0; i < str.length(); i++){
            if (!Character.isDigit(str.charAt(i))){
                return false;
            }
        }
        return true;
    }

    /**
     *
     * @param a 除数
     * @param b 被除数
     * @param scale 保留位数
     * @return 返回
     */
    public static double divide(int a,int b,int scale){
        if(b==0){return 0;}
        return new BigDecimal((float)a/b).setScale(scale, BigDecimal.ROUND_HALF_UP).doubleValue();
    }

}
